package com.mfangsoft.zhuangjialong.integration.biotopeInfo.controller;





import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.facebook.presto.sql.parser.SqlBaseParser.UseContext;
import com.mfangsoft.zhuangjialong.app.entryactivity.model.BaseEntryActivity;
import com.mfangsoft.zhuangjialong.app.entryactivity.service.EntryActivityService;
import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.common.utils.UserSessionUtil;
import com.mfangsoft.zhuangjialong.integration.activity.model.BaseActivityInfo;
import com.mfangsoft.zhuangjialong.integration.activity.model.BaseActivityInfoItem;
import com.mfangsoft.zhuangjialong.integration.activity.model.BaseActivityShop;
import com.mfangsoft.zhuangjialong.integration.activity.service.ActivityService;
import com.mfangsoft.zhuangjialong.integration.biotopeInfo.model.BiotopeInfo;
import com.mfangsoft.zhuangjialong.integration.biotopeInfo.service.BiotopeInfoService;
import com.mfangsoft.zhuangjialong.integration.order.model.BaseOrder;
import com.mfangsoft.zhuangjialong.integration.permission.model.PermissionEntity;
import com.mfangsoft.zhuangjialong.integration.statisticsactivity.model.BaseStatisticsActivity;
import com.mfangsoft.zhuangjialong.integration.statisticsactivity.service.StatisticsActivityService;
import com.mfangsoft.zhuangjialong.integration.user.model.UserEntity;
import com.mfangsoft.zhuangjialong.integration.user.service.UserService;



@Controller
@RequestMapping("/server")
public class BiotopeInfoController {
	

	@Autowired
	BiotopeInfoService biotopeInfoService;

	@RequestMapping(value="/addBiotopeInfoByExcel",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addBiotopeInfoByExcel( MultipartHttpServletRequest request,HttpServletResponse response){
		ResponseMessage<String> message = new ResponseMessage<String>();
	
		try {	
			biotopeInfoService.addBiotopeInfoByExcel(request);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	@RequestMapping(value="/selectBiotopeInfoPage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<Map<String,Object>>> selectBiotopeInfoPage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			message.setResult(biotopeInfoService.selectBiotopeInfoPage(page));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
	}
	
	
	@RequestMapping(value="/updateBiotopeInfo",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateBiotopeInfo(@RequestBody BiotopeInfo biotopeInfo){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {	
			biotopeInfoService.updateBiotopeInfo(biotopeInfo);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	
	@RequestMapping(value="/selectBiotopeInfoById/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String, Object>> updateBiotopeInfo(@PathVariable Integer id){
		ResponseMessage<Map<String, Object>> message = new ResponseMessage<Map<String, Object>>();
		try {	
			message.setResult(biotopeInfoService.selectBiotopeInfoById(id));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	@RequestMapping(value="/getShopByfilialeId/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<Map<String, Object>>> getShopByfilialeId(@PathVariable Integer id){
		ResponseMessage<List<Map<String, Object>>> message = new ResponseMessage<List<Map<String, Object>>>();
		try {	
			message.setResult(biotopeInfoService.getShopByfilialeId(id));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	@RequestMapping(value="/getSellerByShopId/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<Map<String, Object>>> getSellerByShopId(@PathVariable Integer id){
		ResponseMessage<List<Map<String, Object>>> message = new ResponseMessage<List<Map<String, Object>>>();
		try {	
			message.setResult(biotopeInfoService.getSellerByShopId(id));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	@RequestMapping(value="/deleteBiotopeInfoById/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String, Object>> deleteBiotopeInfoById(@PathVariable Integer id){
		ResponseMessage<Map<String, Object>> message = new ResponseMessage<Map<String, Object>>();
		try {	
			biotopeInfoService.deleteBiotopeInfoById(id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
}
